package com.ysqcould.web.controller.allocation;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ysqcould.common.annotation.Log;
import com.ysqcould.common.core.controller.BaseController;
import com.ysqcould.common.core.domain.AjaxResult;
import com.ysqcould.common.core.page.TableDataInfo;
import com.ysqcould.common.enums.BusinessType;
import com.ysqcould.common.utils.poi.ExcelUtil;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ysqcould.allocation.domain.UserRole;
import com.ysqcould.allocation.service.IUserRoleService;

/**
 * 用户--角色Controller
 * 
 * @author ruoyi
 * @date 2022-08-18
 */
@RestController
@RequestMapping("/allocation/userRole")
public class UserRoleController extends BaseController
{
    @Autowired
    private IUserRoleService userRoleService;

    /**
     * 查询用户--角色列表
     */
    @PreAuthorize("@ss.hasPermi('allocation:userRole:list')")
    @GetMapping(value = "/{id}")
    public TableDataInfo list(@PathVariable("id") Long id)
    {
        startPage();
        UserRole userRole=new UserRole();
        userRole.setId(id);
        List<UserRole> list = userRoleService.selectUserRoleList(userRole);
        return getDataTable(list);
    }

    /**
     * 导出用户--角色列表
     */
   /* @PreAuthorize("@ss.hasPermi('allocation:userRole:export')")
    @Log(title = "用户--角色", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, UserRole userRole)
    {
        List<UserRole> list = userRoleService.selectUserRoleList(userRole);
        ExcelUtil<UserRole> util = new ExcelUtil<UserRole>(UserRole.class);
        util.exportExcel(response, list, "用户--角色数据");
    }*/

    /**
     * 获取用户--角色详细信息
     */
   /* @PreAuthorize("@ss.hasPermi('allocation:userRole:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(userRoleService.selectUserRoleById(id));
    }*/

    /**
     * 新增用户--角色
     */
    @PreAuthorize("@ss.hasPermi('allocation:userRole:add')")
    @Log(title = "用户--角色", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody UserRole userRole)
    {
        userRole.setAsId(getUserId());
        return toAjax(userRoleService.insertUserRole(userRole));
    }

    /**
     * 修改用户--角色
     */
    @PreAuthorize("@ss.hasPermi('allocation:userRole:edit')")
    @Log(title = "用户--角色", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UserRole userRole)
    {
        return toAjax(userRoleService.updateUserRole(userRole));
    }

    /**
     * 删除用户--角色
     */
    @PreAuthorize("@ss.hasPermi('allocation:userRole:remove')")
    @Log(title = "用户--角色", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(userRoleService.deleteUserRoleByIds(ids));
    }
}
